package org.zhaolei.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.zhaolei.mapper.BannerMapper;
import org.zhaolei.model.BannerDO;
import org.zhaolei.service.BannerService;
import org.zhaolei.vo.BannerVO;

import java.util.List;
import java.util.stream.Collectors;

@Service
@Slf4j
public class BannerServiceImpl implements BannerService {

    @Autowired
    private BannerMapper bannerMapper;
    @Override
    public List<BannerVO> list() {
        //这里如果不需要排序，就不需要创建QueryWrapper了
        List<BannerDO> list_DO = bannerMapper.selectList(new QueryWrapper<BannerDO>()
                .orderByAsc("weight"));

        List<BannerVO> list_VO = list_DO.stream().map(obj->{
            BannerVO bannerVO = new BannerVO();
            BeanUtils.copyProperties(obj, bannerVO);
            return bannerVO;
        }).collect(Collectors.toList());


        return list_VO;
    }
}
